<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('iurl_title'))
{
    function root_url()
    {
        $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
    	$base_url .= '://'. $_SERVER['HTTP_HOST'];
    	$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
        return $base_url;
    }
}

if ( ! function_exists('root_dir'))
{    
    function root_dir()
    {
        $CI =& get_instance();
    	return $CI->config->slash_item('root_dir');
    }
}

if ( ! function_exists('ianchor'))
{
	function ianchor($uri = '', $title = '', $attributes = '')
	{
		$title = (string) $title;
        if ($uri == '#')
        {
            $site_url = $uri;
        }
        elseif ( ! is_array($uri))
		{
			$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
		}
		else
		{
			$site_url = site_url($uri);
		}

		if ($title == '')
		{
			$title = $site_url;
		}

		if ($attributes != '')
		{
			$attributes = _parse_attributes($attributes);
		}

		return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
	}
}
function babycms_btnAssets($frm = 'frmImage', $field = 'image')
{
    return '<a href="#" class="btnAssets" onclick="mcImageManager.open("'.$frm.'","'.$field.'");">&nbsp; &nbsp; &nbsp;&nbsp;</a>';
}

/**
 * helper sort by header of table in admin
 */
function smHeaderSort($field, $table, $title)
{
  if (isset($_SESSION['sm_sort_'.$table]) && $_SESSION['sm_sort_'.$table]['field'] == $field) {
    return $_SESSION['sm_sort_'.$table]['url']; 
  } 
  return anchor($table.'/sort/'.$field.'/asc', $title);  
}


